function formatDate(date) {   //当前日期
	var year = date.getFullYear()
	var month = date.getMonth() + 1
	var day = date.getDate()
	return [year, month, day].map(formatNumber).join('-')
}

function formatDateAfter(date) {   //当前日期后十年
	var year = date.getFullYear() + 10
	var month = date.getMonth() + 1
	var day = date.getDate()
	return [year, month, day].map(formatNumber).join('-')
}

function formatTime(date) {
	var year = date.getFullYear()
	var month = date.getMonth() + 1
	var day = date.getDate()

	var hour = date.getHours()
	var minute = date.getMinutes()
	var second = date.getSeconds()

	return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
function formatNumber(n) {
	n = n.toString()
	return n[1] ? n : '0' + n
}
//GET请求
function GET(requestHandler, type = '') {
	request('GET', requestHandler)
}
//POST请求
function POST(requestHandler, type = '') {
	request('POST', requestHandler)
}

function request(method, requestHandler) {
	var params = requestHandler.params;
	var app = getApp()
	wx.showLoading({
		title: "正在加载"
	})
	wx.request({
		url: app.globalData.host + requestHandler.url,
		data: params,
		method: method,
		header: {
			'content-type': 'application/json',
		},
		success: function (res) {
			wx.hideLoading()
			requestHandler.success(res)
		},
	})
}
module.exports = {
	formatDate: formatDate,
	formatTime: formatTime,
	GET: GET,
	POST: POST,
}
